/*
 * @Author: nccloud
 * @PageInfo: 删除
 */
import { ajax } from 'nc-lightapp-front';
import { AREA, URL, FIELDS, UISTATUS, DATASOURCECACHE } from '../../constance';
import { showSuccessInfo, showSingleDeleteDialog } from '../../tool/messageUtil';
import { deleteCacheData, getNextId } from '../../tool/cacheDataManager';
import pageInfoClick from './pageInfoClick';

export default function deleteBtnClick(props) {
        // 按钮删除
        showSingleDeleteDialog({
                beSureBtnClick: () => {
                        let reqData = {
                                infos: [
                                        {
                                                id: props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_head_fields).value,
                                                ts: props.form.getFormItemsValue(AREA.cardFormId, FIELDS.ts).value
                                        }
                                ]
                        };

                        ajax({
                                url: URL.delete,
                                data: reqData,
                                success: (res) => {
                                        if (res.success && res.data) {
                                                showSuccessInfo(res.data.message);
                                                let pk = res.data.successIds[0];
                                                let nextId = getNextId(props, pk, DATASOURCECACHE.dataSourceListCacheKey);
                                                // 删除缓存数据
                                                deleteCacheData(props, FIELDS.pk_head_fields, pk, DATASOURCECACHE.dataSourceListCacheKey);
                                                props.setUrlParam({ status: UISTATUS.browse, id: nextId });
                                                pageInfoClick.call(this, props, nextId);
                                        }
                                }
                        });
                }
        });
}
